package com.example.eldersystem.operatedata.mapper;

import com.example.eldersystem.operatedata.model.Employee;
import org.apache.ibatis.annotations.*;
import java.util.List;


public interface EmployeeMapper {

    @Insert("insert into employee_info(username,gender,phone,id_card,birthday,hire_date,resign_date,imgset_dir,profile_photo,description) " +
            "values (#{userName},#{gender},#{phone},#{idCard},#{birthday},#{hireDate},#{resignDate},#{imgsetDir},#{profilePhoto},#{description}) ")
    int addEmployee(Employee employee);


    @Update("update employee_info " +
            "set username=#{userName}," +
            "gender=#{gender}," +
            "phone=#{phone}," +
            "id_card=#{idCard}," +
            "birthday=#{birthday}," +
            "hire_date=#{hireDate}," +
            "resign_date=#{resignDate}," +
            "imgset_dir=#{imgsetDir}," +
            "profile_photo=#{profilePhoto}," +
            "description=#{description} " +
            "where id = #{id}")
    int updateEmployee(Employee employee);

    @Update("update employee_info set profile_photo=#{profilePhoto} where id=#{id}")
    int updateProfile(int id,String profilePhoto);

    @Delete("delete from employee_info where id = #{id}")
    int deleteEmployee(int id);

    @Select("select count(*) from employee_info")
    int selectEmployeeNum();

    @Select("select * from employee_info limit #{from},#{num}")
    @Results(id="select1",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userName",column = "username"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "idCard",column = "id_card"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "hireDate",column = "hire_date"),
            @Result(property = "resignDate",column = "resign_date"),
            @Result(property = "imgsetDir",column = "imgset_dir"),
            @Result(property = "profilePhoto",column = "profile_photo"),
            @Result(property = "description",column = "description"),
    })
    List<Employee> selectEmployee(int from, int num);

    @Select("select count(*) from employee_info where username like concat('%',#{userName},'%')")
    int selectEmployeeNum2(String userName);

    @Select("select * from employee_info where username like concat('%',#{userName},'%')")
    @Results(id="select2",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userName",column = "username"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "idCard",column = "id_card"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "hireDate",column = "hire_date"),
            @Result(property = "resignDate",column = "resign_date"),
            @Result(property = "imgsetDir",column = "imgset_dir"),
            @Result(property = "profilePhoto",column = "profile_photo"),
            @Result(property = "description",column = "description"),
    })
    List<Employee> selectEmployeeByName(String userName);
}
